<template>
	<view class="success_container">
		<view class="mt_62 ml_16 mr_16 br_8 bc_fff ptb_44 plr_12 pr">
			<image class="icon width_66 height_66 br50 pa" src="../../../static/images/success.png" mode=""></image>
			<view class="fz_16 fb fc">
				{{title}}
			</view>
			<view class="info_wrap mt_16">
				<view class="mt_24 fx jcb">
					<text>订单编号</text>
					<text>{{orderNo}}</text>
				</view>
				<view class="mt_8 fx jcb">
					<text>下单时间</text>
					<text>{{createOrderTime}}</text>
				</view>
				<view class="mt_8 fx jcb" v-if="orderType!=6&&orderType!=7">
					<text>可返积分</text>
					<text>{{gainIntegral}}</text>
				</view>
			</view>
			<button class="w100 custom_btn primary lh_44 br_57 mt_24" style="background: linear-gradient(90deg, #FA4704 0%, #FE8D00 100%); font-size: 28rpx;"
				v-if="orderId&&(orderType!=5||(orderType==5&&groupData.status==1))"
				@click="handleUrl('order')">查看订单</button>
			<button class="w100 custom_btn primary lh_44 br_57 mt_24" v-if="orderType==5&&groupData.status==0"
				open-type="share">立即分享</button>
			<button class="w100 custom_btn default lh_44 br_57 mt_16" style="font-size: 28rpx;" @click="handleUrl('integral')" v-if="orderType==6">返回积分商城</button>
			<button class="w100 custom_btn default lh_44 br_57 mt_16" style="font-size: 28rpx;" @click="handleUrl('home')" v-else>返回首页</button>
		</view>
	</view>
</template>

<script>
	import shareMixin from '@/mixins/share.js'
	import api from '@/service/config/api.js'
	import {
		mapState
	} from 'vuex'
	export default {
		mixins: [shareMixin],
		data() {
			return {
				type: '',
				orderType: '',
				createOrderTime: '',
				gainIntegral: 0,
				orderNo: '',
				orderId: '',
				residueCount: 0,
				groupGoodsInitiateId: '',
				goodsId: '',
				groupGoodsRecordId: '',
				userInfo: this.$storage.getItem('basicUnserInfo') || {},
				groupData: {}, // 拼团信息
			}
		},
		computed: {
			...mapState(['userType']),
			serveName() {
				console.log("获取得到",this.$store.state.appType ,this.$base.ADMIN_TYPE);
				return this.$store.state.appType == this.$base.ADMIN_TYPE ? '业务员' : '导购员'
			},
			title() {
				if (this.type == 'order') {
					if(this.orderType == 6||this.orderType==7) {
						return '下单成功，等待平台发货'
					}
					if (this.orderType == 5) {
						if (this.groupData.status == 0) {
							return `还差${this.residueCount||0}人即可开团，快去邀请吧～`
						}
						if (this.groupData.status == 1) {
							return `开团成功，待${this.serveName}确认订单`
						}
					}
					if (this.orderType == 4) {
						return `抢购成功，待${this.serveName}确认订单`
					}
					return `下单成功，待${this.serveName}确认订单`
				}
			}
		},
		onLoad(options) {
			console.log("查看",options.orderType)
			this.type = options.type || ''
			this.orderType = options.orderType || ''
			this.goodsId = options.goodsId || ''
			this.createOrderTime = options.createOrderTime || ''
			this.gainIntegral = options.gainIntegral || 0
			this.orderNo = options.orderNo || ''
			this.orderId = options.orderId || ''
			this.residueCount = options.residueCount || 0
			this.groupGoodsInitiateId = options.groupGoodsInitiateId || ''
			this.groupGoodsRecordId = options.groupGoodsRecordId || ''
			if (this.orderType == 5 && this.groupGoodsRecordId) {
				this.getGroupData()
			}
		},
		methods: {
			// 获取拼团信息
			getGroupData() {
				this.$utils.loading()
				api.get('/goods/api/product/userGroupDetail', {
					id: this.groupGoodsRecordId,
					...this.$store.state.userInfo.customerId ? {
						customerId: this.$store.state.userInfo.customerId
					} : {},
					userType: this.$store.state.userInfo.identityType || 1
				}).then(res => {
					this.groupData = res.data
					this.shareTitle = `您的好友邀您参与【${res.data.productApiDetailVo.productName}】的拼团~`
					this.shareImageUrl = res.data.productApiDetailVo.coverImageUrl || res.data.productApiDetailVo
						.specificationImageUrl
					this.sharePath =
						`/pages/goods/pages/group_info?id=${res.data.id}&customerId=${this.$store.state.userInfo.customerId}`
				})
			},
			handleUrl(type) {
				switch (type) {
					case 'home':
						uni.reLaunch({
							url: '/pages/index/index'
						})
						break
					case 'integral':
						uni.reLaunch({
							url: '/pages/goods/pages/integral'
						})
						break
					case 'order':
						uni.redirectTo({
							url: '/pages/person/pages/order_detail?id=' + this.orderId
						})
					default:
						break
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.success_container {
		.icon {
			top: -58rpx;
			left: 0;
			right: 0;
			margin: 0 auto;
			z-index: 2;
		}

		.info_wrap {
			border-top: 1rpx solid rgba(0, 0, 0, 0.1);
		}
	}
</style>